<div id="tb<?php echo $uniqid;?>" style="padding:5px">
    <table cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td><SELECT id='membersStatus' onchange="membersSearch();" class="forminput inputstyle validatebox-text">
                <OPTION value="-1">所有状态</OPTION>
                <OPTION value="-1" disabled="disabled"> -------- </OPTION>
                <OPTION value="1">激活</OPTION>
                <OPTION value="0">冻结</OPTION>
            </SELECT>
            </td>
            <td><a href="javascript:void(0);" onclick="membersAdd();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="membersEdit();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="membersDelete();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><a href="javascript:void(0);" onclick="membersReload();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
            <td>
                <div class="datagrid-btn-separator"></div>
            </td>
            <td><div style="margin-top: -3px;">
                <span style="line-height:30px;">注册日期</span>
                <input id="members_start_on" type="text" class="easyui-datebox"> </input>至
                <input id="members_end_on" type="text" class="easyui-datebox"> </input>
            </div>
            </td>
            <td>&nbsp;&nbsp;<input id="membersKeywords" placeholder="手机号或名称" style="width:100px" type="text" class="forminput inputstyle"> </input></td>
            <td><a href="javascript:void(0);" onclick="membersSearch();" class="l-btn l-btn-small l-btn-plain"><span
                    class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
        </tr>
        </tbody>
    </table>
</div>
<div class="con" onselectstart="return false;" style="-moz-user-select:none;">
    <table id="members"></table>
</div>
<div id="membersdlg" class="easyui-dialog" title="信息框" style="width: 860px; height: 710px;" closed="true"></div>

<script>
    var membersAdd = function () {
        $("#membersdlg").dialog({
            title: '添加会员',
            closed: false,
            width: 860,
            height: 710,
            cache: false,
            href: '/admin/members/membersadd',
            modal: true,
            buttons: [{
                text: '保存',
                id: 'membersaddsubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#membersdlg").dialog('close');
                }
            }]
        });
    };
    var membersEdit = function () {
        var row = $('#members').datagrid('getSelected');
        if (row) {
            $("#membersdlg").dialog({
                title: '编辑信息',
                closed: false,
                width: 860,
                height: 710,
                cache: false,
                href: '/admin/members/membersedit?id=' + row.id,
                modal: true,
                buttons: [{
                    text: '保存',
                    id: 'memberseditsubmit',
                    iconCls: 'icon-ok',
                }, {
                    text: '关闭',
                    iconCls: 'icon-no',
                    handler: function () {
                        $("#membersdlg").dialog('close');
                    }
                }]
            });
        } else {
            $.messager.alert('提示', '请先选择要编辑的行！', 'warning');
        }
    };
    var membersDirectedit = function (id) {
        $("#membersdlg").dialog({
            title: '编辑信息',
            closed: false,
            width: 860,
            height: 664,
            cache: false,
            href: '/admin/members/membersedit?id=' + id,
            modal: true,
            buttons: [{
                text: '保存',
                id: 'membersupdatesubmit',
                iconCls: 'icon-ok',
            }, {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    $("#membersdlg").dialog('close');
                }
            }]
        });
    };
	var membersOrders = function (members_id) {
		if(typeof($("#orders"))!='undefined'){
			$('#rightTabs').tabs('close','订单浏览');
		}
		addTab('订单浏览', '/admin/orders/orders?members_id='+members_id);
	};
	var membersInviter = function (members_id) {
		if(typeof($("#membersInviter"))!='undefined'){
			$('#rightTabs').tabs('close','分销会员');
		}
		addTab('分销会员', '/admin/members/inviter?members_id='+members_id);
	};
	var membersInviterOrders = function (members_id) {
		if(typeof($("#inviterOrders"))!='undefined'){
			$('#rightTabs').tabs('close','分销订单');
		}
		addTab('分销订单', '/admin/orders/inviterOrders?members_id='+members_id);
	};
    var membersdelete = function () {
        var row = $('#members').datagrid('getSelections');
        var item= [];
        for(var i=0;i<row.length;i++){
            item.push(row[i].id);
        }
        if (row) {
            $.messager.confirm('提示', '确定批量删除选中行吗？', function (r) {
                if (r == true) {
                    $.messager.progress();
                    $.post('/admin/members/membersdelete', {id: item}, function (data) {
                        $.messager.progress('close');
                        if (data.ret == 0) {
                            $.messager.show({
                                title: '提示',
                                msg: data.msg,
                                timeout: 3000,
                                showType: 'slide'
                            });
                            membersreload();
                        } else {
                            $.messager.alert('提示', data.msg, 'warning');
                        }
                    }, 'json');
                }
            });
        } else {
            $.messager.alert('提示', '请选择要删除的行！', 'warning');
        }
    };
    var membersreload = function () {
        $("#members").datagrid('reload');
    };
    var membersSearch = function () {
        var height = $(window).height() - $(".top").height() - 68;//表格高度
        var width = $(window).width() - $(".leftmenu").width() - 13;//表格高度
        $("#members").datagrid({
            title: '会员管理',
            width: width,
            height: height,
            singleSelect: true,//如果为true，则只允许选择一行
            striped: true,//是否显示斑马线效果。
            rownumbers: true,//如果为true，则显示一个行号列。
            pagination: true,//是否显示分页
            pageSize: 20,
            pageList: [20, 25, 30, 35],
            method: 'post',
            sortName: 'created_at',
            sortOrder: 'desc',
            url: '/admin/members/membersGet/',
            queryParams: {status:$('#membersStatus').val(),keywords: $('#membersKeywords').val(),start_on:$('#members_start_on').val(),end_on:$('#members_end_on').val()},
            fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
            selectOnCheck: true,
            checkOnSelect: true,
            toolbar: '#tb<?php echo $uniqid;?>',
            rowStyler: function (index, row) {
                if (row.status == 0) {
                    return 'color:#dc324d;';
                }
            },
            columns: [[
                {field: 'phone', title: '会员', width: '15%', formatter: function (value, rowData, rowIndex){
                        return rowData.phone?rowData.phone:'' + ' ' + rowData.name;
                    }
                },
                {
                    field: 'avatar', title: '头像', width: '5%', align:'center', formatter: function (value, rowData, rowIndex) {
                        if (value != '') {
                            return '<img src="' + value + '?imageView2/1/w/60/h/60" style="height:60px;width:60px;">';
                        } else {
                            return '';
                        }
                    }
                },
				{field: 'rankName', title: '会员等级', width: '7%'},
				{field: 'score', title: '积分', width: '10%', sortable: true},
				{field: 'money', title: '账户余额', width: '10%', sortable: true},
				{field: 'status', title: '状态', width: '5%', align:'center', formatter: function (value, rowData, rowIndex){
				        return value==1 ? '激活' : '冻结';
                    }
                },
                {field: 'created_at', title: '注册时间', width: '8%', sortable: true},
                {field: 'logined_at', title: '最后登陆', width: '8%', sortable: true},
				{field: 'paid_at', title: '最后下单', width: '8%'},
                {field: 'action', title: '操作', width: '10%', formatter: function (value, rowData, rowIndex) {
                        if (value != '') {
                            return '<a href="javascript:;" class="l-btn l-btn-small" onclick="membersDirectedit('+rowData.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">编辑</span><span class="l-btn-icon icon-ok">&nbsp;</span></span></a>&nbsp;&nbsp;<a href="javascript:;" class="l-btn l-btn-small" onclick="membersOrders('+rowData.id+')" ><span class="l-btn-left l-btn-icon-left"><span class="l-btn-text" style="margin-left:15px">订单</span></span></a>';
                        }
                    }
                },
            ]],
			onDblClickRow : function(index,field){
				membersEdit();
			}
        });
    }
    membersSearch();
</script>
